#include <iostream>
#include <string>
#include <vector>

using namespace std;
class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int profit = 0;
        int tmp_profit = 0;

        for (size_t i = 0; i < prices.size();) {
            
            for (size_t j = i+1; j < prices.size(); j++) {
                if (prices[j] - prices[i] > tmp_profit) {
                    tmp_profit = prices[j] - prices[i];

                    if (j == prices.size() - 1) {
                        profit += tmp_profit;
                        i = j;
                        break;
                    }
                }
                else {
                    profit += tmp_profit;
                    tmp_profit = 0;
                    i = j;
                    break;
                }
            }
            if (i == prices.size() - 1) {
                break;
            }
        }

        return profit;
    }
};


int main(int argc, char* argv[]) {
    Solution solution;
    vector<int> prices = {1, 2, 3, 4, 5};
    int result = solution.maxProfit(prices);
    cout << "Result: " << result << endl;
    return 0;
}